import api from '@api/mop_api';
import { toast, log, err } from '@utils/wxapi';
Page({
  data: {
    page: 1,
    size: 20,
    list: [],
    user: {},
  },
  async onLoad() {
    await this.bill();
  },
  async bill() {
    const { page, size } = this.data;
    try {
      const { respCode, source, pageTotal,msg } = await api.payflowList({ page, size });
      if (respCode === 200) {
        const list = JSON.parse(source);
        log(list);
        if (this.data.list.length === 0) {
          this.setData({ list, pageTotal });
        } else {
          const newlist = [...this.data.list, ...list];
          this.setData({ list: newlist, pageTotal });
        }
      }else{
        throw new Error(msg);
      }
    } catch (error) {
      err(error);
      throw error;
    }
  },
  onReachBottom() {
    const { list, pageTotal, page } = this.data;
    if (list.length < pageTotal) {
      this.setData({ page: page + 1 });
      this.bill();
    } else {
      toast('已加载全部数据');
    }
  },
});
